package com.bestcem.xm.user.dao.impl;

import com.bestcem.xm.user.dao.UserMfaRoleDao;
import com.bestcem.xm.user.dao.mapper.UserMfaRoleMapper;
import com.bestcem.xm.user.entity.pojo.UserMfaRoleDO;
import com.bestcem.xm.user.util.business.DataBaseUtil;
import com.bestcem.xm.user.util.convert.UserMfaRoleConvert;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户登录安全验证关联角色 Dao
 *
 * @author panyun <yun.pan@idiaoyan.com>
 * @version v1.0
 * @date 2022/6/13 10:36
 */
@Repository
public class UserMfaRoleDaoImpl implements UserMfaRoleDao {
    @Resource
    private UserMfaRoleConvert userMfaRoleConvert;

    @Resource
    private UserMfaRoleMapper userMfaRoleMapper;

    @Override
    public List<UserMfaRoleDO> listByCondition(UserMfaRoleDO userMfaRole) {
        return userMfaRoleConvert.mysqls2Dos(userMfaRoleMapper.listByCondition(userMfaRoleConvert.do2Mysql(userMfaRole)));
    }

    @Override
    public int insertSelective(UserMfaRoleDO userMfaRole) {
        DataBaseUtil.setCreateAndUpdateTime(userMfaRole);
        return userMfaRoleMapper.insertSelective(userMfaRoleConvert.do2Mysql(userMfaRole));
    }

    @Override
    public int deleteByRoleIds(String orgId, List<String> deleteRoleIds) {
        if (CollectionUtils.isEmpty(deleteRoleIds)) {
            return 0;
        }
        return userMfaRoleMapper.deleteByRoleIds(orgId, deleteRoleIds);
    }
}
